
var codeObj = {

    /**
     * 描述 : 库名选择事件
     * 作者 : Zoro.Zhu
     */
    'schemaChange': function (schema) {
        $.ajax({
            type: "post",
            url: ROOT_URL + "/?c=ctrl_codeGenerator&a=getFromName",
            cache:false,
            async:true,
            data:{schema: schema},
            dataType: "json",
            success: function(result){
                if(result.state === 200){
                    var selectStr = '<option value="">=请选择=</option>';
                    for(var i in result.data){
                        selectStr += "<option value='" + result.data[i].TABLE_NAME + "'>" + result.data[i].TABLE_NAME + "</option>";
                    }
                    $('#fromName').html(selectStr);
                }
            }
        });
    },

    /**
     * 描述 : 表名选择事件
     * 作者 : Zoro.Zhu
     */
    'fromNameChange' : function (fromName) {
        var schema = $('#schema').val();
        $.ajax({
            type: "post",
            url: ROOT_URL + "/?c=ctrl_codeGenerator&a=getColumnList",
            cache:false,
            async:true,
            data:{schema: schema,fromName:fromName},
            dataType: "json",
            success: function(result){
                if(result.state === 200){
                    var tableStr = '<form action="" id="generatorFrom" class="search-form">' +
                        '<input type="hidden" name="fromName" value="' + fromName + '">' +
                        '功能名称:<input type="text" name="tableName" value="' + result.tableName + '">' +
                        '是否要新增修改<input type="radio" name="insertUpdate" value="1" checked>是<input type="radio" name="insertUpdate" value="2">否' +
                        '作者：<input type="text" name="author">' +
                        '<table class="table">' +
                        '                <tr>' +
                        '                    <td>字段名</td>' +
                        '                    <td>注释</td>' +
                        '                    <td>字段类型</td>' +
                        '                    <td>主键</td>' +
                        '                    <td>列表是否展示</td>' +
                        '                    <td>是否要排序</td>' +
                        '                    <td>新增修改是否必填</td>' +
                        '                    <td>查询方式</td>' +
                        '                </tr>';
                    for(var i in result.data){
                        tableStr += "<tr>";
                        tableStr += "<td>" + result.data[i].COLUMN_NAME + "</td>";
                        tableStr += "<td><input name='comment[" + result.data[i].COLUMN_NAME + "]' value='" + result.data[i].COLUMN_COMMENT + "'></td>";
                        tableStr += "<td><input name='type[" + result.data[i].COLUMN_NAME + "]' value='" + result.data[i].DATA_TYPE + "'></td>";
                        tableStr += "<td><input name='key[" + result.data[i].COLUMN_NAME + "]' value='" + result.data[i].COLUMN_KEY + "' readonly></td>";
                        tableStr += "<td><input type='radio' name='exhibition[" + result.data[i].COLUMN_NAME + "]' value='1' checked>是<br>" +
                            "<input type='radio' name='exhibition[" + result.data[i].COLUMN_NAME + "]' value='2' >否</td>";
                        tableStr += "<td><input type='radio' name='sort[" + result.data[i].COLUMN_NAME + "]' value='1' >是<br>" +
                            "<input type='radio' name='sort[" + result.data[i].COLUMN_NAME + "]' value='2' checked>否</td>";
                        tableStr += "<td><input type='radio' name='mustFill[" + result.data[i].COLUMN_NAME + "]' value='1' >是<br>" +
                            "<input type='radio' name='mustFill[" + result.data[i].COLUMN_NAME + "]' value='2' checked>否</td>";
                        tableStr += "<td><select name='query[" + result.data[i].COLUMN_NAME + "]'>" +
                            "<option value=''>=不查询=</option>" +
                            "<option value='='>等于</option>" +
                            "<option value='LIKE'>模糊查询</option>" +
                            "<option value='>=+<='>大于等于+小于等于</option>" +
                            "</select></td>";
                        tableStr += "</tr>";
                    }
                    tableStr += "</table></form>";
                    $('#fromList').html(tableStr);
                }
            }
        });
    },

    /**
     * 描述：开始生成代码
     * 作者：Zoro.Zhu
     * **/
    'codeGenerator' : function () {
        var data = $("#generatorFrom").serialize();
        if(data.includes('exhibition') !== true){
            window.L.open('tip')('请先选择表名',2000);
            return false;
        }
        $.ajax({
            url: ROOT_URL + "/?c=ctrl_codeGenerator&a=codeGenerator",
            type: "POST",
            cache:false,
            async:true,
            data: data,
            dataType: "json",
            success: function (result) {
                window.L.open('tip')(result.info,4000);
            }
        });
    }

};

